package com.example.maastock.web;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.example.maastock.ontime.SearchOnLine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.mail.MailMessage;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.web.client.RestTemplate;

@Service
public class FeiShuMessageServiceImpl {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private SearchOnLine  searchOnLine;

    public void sendMessage (String message){
// 设置请求头
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);

        FeiShuObject feiShuObject = new FeiShuObject();
        feiShuObject.setMsg_type("text");
        MessageDetail messageDetail = new MessageDetail();
        messageDetail.setText(message);

        feiShuObject.setContent(JSONUtil.toJsonStr(messageDetail));

        HttpEntity<FeiShuObject> entity = new HttpEntity<>(feiShuObject, headers);
        String url = "https://open.feishu.cn/open-apis/bot/v2/hook/d8b91d20-68a3-4d9f-8eff-9b4e808cd8bb";
        Object object1 = restTemplate.postForObject(url, entity, Object.class);
        System.out.println(object1);


    }

    public String spellMessage (String code){
        Object o = searchOnLine.searchOnlineInTime(code);
        if (ObjectUtil.isEmpty(o)){
            return null;
        }
        String string = o.toString();
        return null;
    }
}
